
declare var cocosAnalytics;

export module GCAnalytics {

    function hasCocosAnalytics() {
        if (CC_DEV) {
            return false;
        }
        return true;
    }

    export function onStarted() {
        hasCocosAnalytics() &&
            cocosAnalytics.CACustomEvent.onStarted("经典", {
                name: "开始",
            });
    }

    export function onSuccess(hearts: number) {
        hasCocosAnalytics() &&
            cocosAnalytics.CACustomEvent.onSuccess("经典", {
                name: "结算",
                hearts: hearts
            });
    }

    export function onFailed(message: string) {
        hasCocosAnalytics() &&
            cocosAnalytics.CACustomEvent.onFailed("经典", {
                name: "失败",
                reason: message
            }, "游戏异常");
    }

    export function loginStart() {
        // 开始登陆
        hasCocosAnalytics() &&
            cocosAnalytics.CAAccount.loginStart({
                channel: 'canace-h5',   // 获客渠道，指获取该客户的广告渠道信息   
            });
    }

    /**
     * 
     * @param userId 
     * @param age 
     * @param sex  // 性别：1为男，2为女，其它表示未知
     */
    export function loginSuccess(userId: string, age: number, sex: number) {
        hasCocosAnalytics() &&
            cocosAnalytics.CAAccount.loginSuccess({
                userID: userId,
                age: age,
                sex: sex,
                channel: 'canace-h5',
            })
    }

    export function logout() {
        hasCocosAnalytics() &&
            cocosAnalytics.CAAccount.logout();
    }

    export function init() {
        hasCocosAnalytics() &&
            cocosAnalytics.init({
                appID: '683944542',
                appSecret: 'gc-4-april',
                channel: 'H5',
                version: '1.0.0',
                storeID: 'hellgeniuss',
                engine: 'cocos',
                callNumber: '2022'
            });
    }

}
